<template >
	<view class="" style="padding: 0 20px;">
		<u-form :model="form" ref="uForm">
			<!-- 输入标题 -->
			<u-form-item label="标题:"><u-input placeholder="无" v-model="form.title" disabled="true" type="text" border="true" clearable/></u-form-item>
			<!-- 重要等级 -->
			<u-form-item label-width="150rpx" label="重要等级:">
				<u-input v-model="form.radio" disabled="true" type="text" border="true" clearable/>
			</u-form-item>
			<!-- 选择时间 -->
			<u-form-item label-width="150rpx" label="发布时间:" >
				<u-input v-model="form.time" disabled="true" border="true" clearable/>
			</u-form-item>
			<!-- 输入内容 -->
			<u-form-item label="内容:"><u-input v-model="form.content" disabled="true" type="textarea" border="true" height="200" auto-height="true" clearable="false"/></u-form-item>
		</u-form>
		<view class="">
			<view class="" style="display: flex; justify-content: space-around">
				<view class="button" :class="[buttonChange== true? 'buttonChange':'buttonUnChange']" @click="button1">未读</view>
				<view class="button" :class="[buttonChange== true? 'buttonUnChange':'buttonChange']" @click="button2">已读</view>
			</view>
			<scroll-view scroll-y="true"style="width: 100%; height: 80px; margin-top: 5px;border: 1px solid #ececec;" >
				<view v-if="!read" v-for="(item1,index) in unreadUser" :key="index" >{{item1.realname}}</view>
				<view v-if="read" v-for="(item2,index) in readUser" :key="index" >{{item2.realname}}</view>
			</scroll-view>
		</view>
		<!-- 回复消息列表 -->
		<view class="">
			<view class="" style="margin-top: 10px; color: #007AFF;font-size: 16px;">回复（{{replyMessage.length}}）</view>
			<view class=""v-for="(item,index) in replyMessage" :key="index" style="border-bottom: 1px solid #ececec;">
				<view class="" style="margin-top: 10px; display: flex; color: #999999;">
					<view class="">
						{{item.userId_dictText}}
					</view>
					<view class="" style="margin-left: 20px;">
						{{item.updateTime}}
					</view>
				</view>
				<scroll-view scroll-y="true" style="width: 100%; height: 50px;margin-top:4px: 1px solid #ececec;" >
					<view>{{item.replyContent}}</view>
				</scroll-view>
			</view>
		</view>
		<!-- 回复消息 -->
		<view class="" style="margin-top: 10px;">
			<u-input v-model="messageValue" type="textarea" border="true" height="100" auto-height="true" maxlength="999" clearable/>
			<view class="" style="display: flex; justify-content: space-between;margin: 20px 0 50px;">
				<u-button >取消</u-button>
				<u-button type="primary" @click="reply">回复</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import newsReply from '../../api/newsReply.js'
	export default {
		data() {
			return {
				form:{
					title:'',
					radio:'',
					users:'',
					time:'',
					content:''
				},
				unreadUser:[{realname:'无'}],
				readUser:[{realname:'无'}],
				read:false,
				id:'',
				buttonChange:true,
				replyMessage:[],
				messageValue:''
			}
		},
		onReady() {
			//获取上一页面传递的数据
			const data = this.$Route.query
			 console.log(data)
			 this.form.content = data.message.content
			 this.form.radio = data.message.status_dictText
			 this.form.time = data.message.createTime
			 this.form.title = data.message.title
			 this.id = data.message.id
			 
			 //请求未读/已读消息用户
			 this.button2()
			 this.button1()
			 
			//获取回复消息列表
			 this.Message()
		},
		onLoad(){
			
		},
		methods: {
			//请求未读消息用户
			button1(){
					this.buttonChange = true
					this.read = false
					newsReply.unreadUser({
						'X-Access-Token': this.$store.state.token
					},{'id':this.id}).then(res =>{
						if(res.data.result.length != 0){
							this.unreadUser = res.data.result
						}
					}).catch(err =>{
						console.log(err)
					})
			},
			//请求已读消息用户
			button2(){
					this.buttonChange = false
					this.read = true
					newsReply.readUser({
						'X-Access-Token': this.$store.state.token
					},{'id':this.id}).then(res =>{
						if(res.data.result.length != 0){
							this.readUser = res.data.result
						}
					}).catch(err =>{
						console.log(err)
					})
			},
			//请求消息回复列表
			Message(){
				newsReply.replyMessage({
						'X-Access-Token': this.$store.state.token
					},{'id':this.id,'pageSize':999}).then(res =>{
						if(res.data.result.records.length != 0){
							this.replyMessage = res.data.result.records
						}
					}).catch(err =>{
						console.log(err)
					})
			},
			reply(){
				newsReply.replyNews({
					'X-Access-Token': this.$store.state.token
				},{
					newId:this.id,userId:this.$store.state.userInfo.id,replyContent:this.messageValue
					}).then(res =>{
					}).catch(err =>{
						console.log(err)
				})
				setTimeout(()=>{
					this.Message()
				},100)
				
				this.messageValue=''
			}
		}
	}
</script>

<style lang="scss" scoped>
	.button{
		color: #1e1e1e;
		width: 80px;
		height: 30px;
		line-height: 30px;
		text-align: center;
	}
	.buttonChange{
		// background-color: #007AFF;
		border-bottom:2px solid #007AFF;
	}
	.buttonUnChange{
		// background-color: #e7e7e7;
		border-bottom:2px solid #e7e7e7;
	}
</style>
